package com.pwx.student.service.impl;

import com.pwx.student.common.Const;
import com.pwx.student.common.ResponseResult;
import com.pwx.student.dao.RcAdminMapper;
import com.pwx.student.dao.RcStudentMapper;
import com.pwx.student.dao.RcTeacherMapper;
import com.pwx.student.entity.RcStudent;
import com.pwx.student.service.IRcSystemService;
import com.pwx.student.service.bo.LoginServiceBo;
import com.pwx.student.vo.input.LoginInputVo;
import com.pwx.student.vo.output.LoginOutputVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * Copyright (C),2021-2022,亚瑟王
 * FileName: IRcSystemServiceImpl
 * Author: saber
 * Date:2022/10/25 21:01
 */
@Service
public class IRcSystemServiceImpl implements IRcSystemService {
    @Autowired
    private RcStudentMapper studentMapper;
    @Autowired
    private RcTeacherMapper teacherMapper;
    @Autowired
    private RcAdminMapper adminMapper;
    @Autowired
    private LoginServiceBo loginServiceBo;

    @Override
    public ResponseResult login(LoginInputVo inputVo) {
        LoginOutputVo outputVo = loginServiceBo.doLogin(inputVo);
        if (outputVo!=null){
            if (outputVo.getType().equals(Const.UserType.STUDENT)){
                studentMapper.updateById( new RcStudent(outputVo.getUserId(), LocalDateTime.now()));
            }
            return ResponseResult.createSuccess(outputVo);
        }
        return ResponseResult.createFail("登录失败用户名或密码有误");
    }
}
